home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / blankery / bserverdir / sources / clients / starfield.c < prev   
C/C++ Source or Header  |  1994-11-29  |  3KB  |  132 lines

  1. ;/*
  2. sc StarField.c DATA=FAR NMINC STRMERGE NOSTKCHK IGNORE=73 STRUCTUREEQUIVALENCE NOSTDIO
  3. slink from LIB:c.o StarField.o to //Clients/StarField LIB LIB:sc.lib LIB:amiga.lib /lib/client.lib SC SD NOICONS STRIPDEBUG
  4. delete starfield.o
  5. quit
  6.  
  7.  StarField 1.2  (Client for BServer)
  8.  
  9.  Copyright © 1994 by Stefano Reksten of 3AM - The Three Amigos!!!
  10.  All rights reserved.
  11. */
  12.  
  13. #include <exec/types.h>
  14. #include <intuition/intuition.h>
  15.  
  16. #include <clib/exec_protos.h>
  17. #include <clib/intuition_protos.h>
  18. #include <clib/graphics_protos.h>
  19. #include <clib/alib_protos.h>
  20.  
  21. #include "/include/client.h"
  22.  
  23. struct IntuitionBase *IntuitionBase;
  24. struct GfxBase *GfxBase;
  25.  
  26. struct DisplayIDInformation *dinfo;
  27.  
  28. struct Screen *scr;
  29.  
  30. UWORD Stars[512][2];
  31.  
  32.  
  33. void DrawStars( void )
  34. {
  35. UWORD n, tmpx, trnd, swidth, sheight;
  36. struct Rectangle *rect;
  37. register PLANEPTR plane0, plane1;
  38. register UWORD last_star;
  39.  
  40. rect = GETTXTOSCANRECT(dinfo);
  41.  
  42. swidth = RECTANGLEWIDTH(rect);
  43. sheight = RECTANGLEHEIGHT(rect);
  44.  
  45. if ( DISPLAYID( dinfo ) & LACE )
  46.     last_star = ( sheight > 512 ? 512 : sheight );
  47. else
  48.     last_star = ( sheight > 256 ? 256 : sheight );
  49.  
  50. swidth = (swidth>>8)<<8;
  51.  
  52. if ( scr = OpenScreenTags( NULL,
  53.     SA_DisplayID, DISPLAYID( dinfo ),
  54.     SA_Width, swidth,
  55.     SA_Height, sheight,
  56.     SA_Left, (RECTANGLEWIDTH(rect) - swidth)/2,
  57.     SA_Top, 0,
  58.     SA_Depth, 2,
  59.     SA_Overscan, OSCAN_TEXT,
  60.     SA_Type, CUSTOMSCREEN,
  61.     SA_Quiet, TRUE,
  62.     TAG_END ) )
  63.     {
  64.     register struct ViewPort *vp = &(scr->ViewPort);
  65.  
  66.     SpritesOff();
  67.  
  68.     SetRGB4( vp, 0, 0, 0, 0 );
  69.     SetRGB4( vp, 1, 3, 3, 3 );
  70.     SetRGB4( vp, 2, 6, 6, 6 );
  71.     SetRGB4( vp, 3, 9, 9, 9 );
  72.  
  73.     for ( n = 0; n < last_star; n++ )
  74.         {
  75.         Stars[n][0] = RangeRand(swidth-1);
  76.         Stars[n][1] = RangeRand( 7 );
  77.         }
  78.  
  79.     while( STILL_BLANKING )
  80.         {
  81.         /* Draw stars */
  82.         plane0 = scr->RastPort.BitMap->Planes[0];
  83.         plane1 = scr->RastPort.BitMap->Planes[1];
  84.  
  85.         WaitTOF();
  86.         for ( n = 0; n < last_star; n++ )
  87.             {
  88.             * (plane0 + (Stars[n][0]>>3) ) = 0;
  89.             * (plane1 + (Stars[n][0]>>3) ) = 0;
  90.  
  91.             tmpx = Stars[n][0] + Stars[n][1];
  92.             if ( tmpx >= swidth )
  93.                 {
  94.                 while ( !(trnd = RangeRand( 7 ) ) );
  95.                 Stars[n][0] = 0;
  96.                 Stars[n][1] = trnd;
  97.                 }
  98.             else    Stars[n][0] = tmpx;
  99.  
  100.             if ( Stars[n][1]>>1 & 1 )
  101.                 * (plane0 + (Stars[n][0]>>3) ) = 128>>(Stars[n][0] & 7);
  102.             if ( Stars[n][1]>>1 & 2 )
  103.                 * (plane1 + (Stars[n][0]>>3) ) = 128>>(Stars[n][0] & 7);
  104.  
  105.             plane0 += swidth >>3;
  106.             plane1 += swidth >>3;
  107.             }
  108.         }
  109.     CloseScreen( scr );
  110.     SpritesOn();
  111.     }
  112. else
  113.     SendClientMsg( ACTION_FAILED );
  114. }
  115.  
  116. void __main( char *line )
  117. {
  118. if ( IntuitionBase = (struct IntuitionBase *)OpenLibrary( "intuition.library", 37L ) )
  119.     {
  120.     if ( GfxBase = (struct GfxBase *)OpenLibrary( "graphics.library", 37L ) )
  121.         {
  122.         if ( dinfo = OpenCommunication() )
  123.             {
  124.             DrawStars();
  125.             CloseCommunication( dinfo );
  126.             }
  127.         CloseLibrary( (struct Library *)GfxBase );
  128.         }
  129.     CloseLibrary( (struct Library *)IntuitionBase );
  130.     }
  131. }
  132.